<?php

class SignupController extends ControllerBase
{
    public function initialize()
    {
        $this->tag->setTitle('注册');
        parent::initialize();
    }

    public function indexAction()
    {
        
    }

    public function signupAction()
    {
    	if ($this->request->isPost()) 
    	{
    		$username = $this->request->getPost("username");
    		$password = $this->request->getPost("password");
    		$student_no = $this->request->getPost("student_no");
            //init to normal
            $role = 1;

            //检查sql注入
            if($this->inject_check($username)){
                echo 'sql';
                return;
            }

    		$user = new Users();
    		try{
    		 	$user->setName($username);
    		 	$user->setPasswd($password);
    		 	$user->setStudent_no($student_no);
                $user->setRole($role);

    		 	$success = $user->save();
    		 	if($success) 
    		 	{
    		 		echo "success";
    		 	}
    		 	else
    		 	{
    		 		foreach ($user->getMessages() as $message) 
    		 		{
                		echo $message->getMessage(), "<br/>";
            		}
    		 	}
    		}catch (Exception $e){
				echo $e->getMessage();
			}
    	}
    }
}
